package main

import "fmt"

type queue struct {
	arr []int
	putIndex int
	pollIndex int
	len int
}

func BuildQueue(size int) *queue {
	return &queue{
		arr: make([]int, 0, size),
	}
}

func (q *queue) Put(i int) bool {
	if q.len == cap(q.arr) {
		fmt.Println("this queue is full, cant put element in")
		return false
	}
	q.arr[q.putIndex] = i
	q.len += 1
	if q.putIndex == cap(q.arr) - 1 {
		q.putIndex = 0
	} else {
		q.putIndex += 1		
	}
	return true
}

func (q *queue) Poll() int {
	if q.len == 0 {
		fmt.Println("this queue is empty")
		return -1
	}
	res := q.arr[q.pollIndex]
	q.len -= 1
	if q.pollIndex == cap(q.arr) - 1 {
		q.pollIndex = 0
	} else {
		q.pollIndex += 1
	}
	return res
}

func main() {
	q := BuildQueue(5)
	fmt.Println(q.Poll())
	q.Put(2)
	q.Put(3)
	q.Put(4)
	q.Put(5)
	q.Put(6)
	q.Put(7)
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	q.Put(8)
	q.Put(9)
	q.Put(10)
	fmt.Println(q.arr)
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
	fmt.Println(q.Poll())
}